{include file="common/mini-header" title="权限节点"}
<div class="layui-body">
	<!-- 内容主体区域 -->

	<form class="layui-form" action="" style="max-width: 800px;width: 90%;">
		<div class="layui-form-item">
			<label class="layui-form-label">父级</label>
			<div class="layui-input-inline" style="width: 200px;">
				<select name="pid" lay-verify="required"> 
					{:buildRoleSelect(0,'',$roleInfo['pid'])}
				</select>
			</div>
		</div>		
		<div class="layui-form-item">
			<label class="layui-form-label">角色名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" required lay-verify="required" placeholder="请输入菜单名称" value="{$roleInfo['name']}" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" id="roleId" name="id" value="{$roleInfo['id']}">
				{if condition="$roleInfo['rule_ids'] eq '*'"}
				<a class="layui-btn layui-btn-disabled" title="超级管理员不可以编辑">不可编辑</a>
				{else /}
				<button class="layui-btn" lay-submit lay-filter="edit">编辑并选择权限</button>
				{/if}
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				<button class="layui-btn layui-btn-danger" type="button" style="float:right" id="delBtn" >删除</button>
			</div>
		</div>
	</form>

</div>
<script>
	layui.use('form', function() {
		var form = layui.form;
		var $ = layui.jquery;
		var layer = layui.layer;
		var roleId = $('#roleId').val(); 

		//监听提交
		form.on('submit(edit)', function(data) {
			$.post('./edit', data.field, function(rs) {
				if (rs.code==1) {
					layer.msg(rs.msg)
					window.location.href = rs.url
				} else {
					layer.alert(rs.msg)
				}
			})
			return false;
		});
		
		$(document).ready(function(){
			$('#delBtn').on('click',function(){
				layer.confirm('确定删除吗??', function(index){ 
				  if(index == 1){ //确定
					  $.ajax({
						url: './delete',
						type: 'DELETE',
						data: {id:roleId},
						success:function(rs){
							layer.msg(rs.msg)
							if(rs.code == 1){ 
								setTimeout(function() { 
									parent.location.reload();
								}, 400)
							}
						}
					  }); 
				  }
				  layer.close(index);
				});       
			})
		})
 
		
	});
</script>
{include file="common/footer"}
